<template>
    <div>
        <home-header></home-header>
        <home-swiper :list="swiperList"></home-swiper>
        <home-icons :list="iconList"></home-icons>
        <home-recomment :list="recommentList"></home-recomment>
        <home-weekend :list="weekendList"></home-weekend>
    </div>
</template>

<script>
import axios from 'axios'
import { mapState } from 'vuex'
import HomeHeader from './components/HomeHeader'
import HomeSwiper from './components/HomeSwiper'
import HomeIcons from './components/HomeIcons'
import HomeRecomment from './components/HomeRecomment'
import HomeWeekend from './components/HomeWeekend'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecomment,
    HomeWeekend
  },
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommentList: [],
      weekendList: [],
      lastCity: ''
    }
  },
  methods: {
    getHomeInfo: function () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
        .catch(function (error) {
          console.log(error)
        })
    },
    getHomeInfoSucc: function (res) {
      // console.log(res)
      if (res.data.ret && res.data.data) {
        // console.log('6666')
        const data = res.data.data
        // 城市数据
        this.swiperList = data.swiperList
        this.iconList = data.iconList
        this.recommentList = data.recommentList
        this.weekendList = data.weekendList
      }
    }
  },
  computed: {
    ...mapState(['city'])
  },
  mounted () {
    this.getHomeInfo()
    this.lastCity = this.city
  },
  activated () {
    // console.log('activated')
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style scoped>
</style>
